home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / akcl / kcl.lha / c / interrupt.c < prev    next >
C/C++ Source or Header  |  1987-06-04  |  3KB  |  129 lines

  1. /*
  2. (C) Copyright Taiichi Yuasa and Masami Hagiya, 1984.  All rights reserved.
  3. */
  4.  
  5. /*
  6.     interrupt.c
  7.     DG-SPECIFIC
  8. */
  9.  
  10. #include <sysid.h>
  11. #include <packets:normal_io.h>
  12. #include <packets:task.h>
  13.  
  14. #include "^h:pio.h"
  15.  
  16. #include "include.h"
  17.  
  18. #define WAIT_TIME    1000
  19.  
  20. object SVinterrupt_enable;                    /**/
  21.  
  22. short    wait_stack[100];
  23.  
  24. char    *stdin_system_buf;
  25. struct _iobuf
  26.     stdin_system;
  27.  
  28. init_interrupt()
  29. {
  30.     stdin_system_buf = _fdl[stdin->_fd]->pkt.nio.ibad;
  31.     stdin_system = *stdin;
  32. }
  33.  
  34. init_interrupt1()                        /**/
  35. {                                /**/
  36.     SVinterrupt_enable                    /**/
  37.     = make_si_special("*INTERRUPT-ENABLE*", Ct);        /**/
  38. }                                /**/
  39.  
  40. sigint()
  41. {
  42. /**************************************************************
  43.     avoid trap of C library read routine.
  44. ***************************************************************/
  45.     _fdl[stdin->_fd]->pkt.nio.ibad = stdin_system_buf;
  46.     *stdin = stdin_system;
  47. /**************************************************************/
  48.     interrupt_flag = FALSE;
  49.     terminal_interrupt(FALSE);
  50. }
  51.  
  52. wait_task()
  53. {
  54.     int ac0, ac1, ac2, ier;
  55.  
  56.     interrupt_flag = FALSE;
  57.     interrupt_enable = FALSE;    /* FALSE while initializing */
  58.  
  59.     while (!interrupt_enable) {    /* wait for initializing end */
  60.         ac0 = 100;
  61.         sys($WDELAY, &ac0, &ac1, &ac2);
  62.     }
  63. LOOP:
  64.     sys($INTWT, &ac0, &ac1, &ac2);
  65.  
  66.  
  67. /*
  68.     When ^C^A is typed, if the value of SI:*INTERRUPT-ENABLE* is NIL,
  69.     SI:*INTERRUPT-ENABLE* is set to T and the interrupt is ignored.
  70.     By checking the value of SI:*INTERRUPT-ENABLE*,
  71.     the program can control its flow according to terminal interrupts.
  72.     It may have to reset the value of SI:*INTERRUPT-ENABLE*
  73.     for processing successive interrupts.
  74.     If ^C^A is typed twice (or more times) consecutively, however,
  75.     the control will go through the following if statement,
  76.     and the interrupt will be processed in the usual way, i.e.
  77.     an error will be signalled.
  78. */    
  79.     if (symbol_value(SVinterrupt_enable) == Cnil) {        /**/
  80.         SVinterrupt_enable->s.s_dbind = Ct;        /**/
  81.         goto LOOP;                    /**/
  82.     }                            /**/
  83.  
  84.     interrupt_flag = TRUE;
  85.  
  86.     ac0 = WAIT_TIME;
  87.     sys($WDELAY, &ac0, &ac1, &ac2);
  88.  
  89.     if (interrupt_flag) {
  90.         while (!interrupt_enable) {
  91.             ac0 = 100;
  92.             sys($WDELAY, &ac0, &ac1, &ac2);
  93.         }
  94.         ac0 = sigint;
  95.         ac1 = 1;
  96.         sys($IDGOTO, &ac0, &ac1, &ac2);
  97.     }
  98.  
  99.     goto LOOP;
  100. }
  101.  
  102. /*
  103.     $signal$init is called from C library
  104. */
  105. $signal$init()
  106. {
  107.     P_TASK    taskp;
  108.     int ac0, ac1, ac2, ier;
  109.  
  110.     taskp.dlnk = 1;
  111.     taskp.dlnkb = 0;
  112.     taskp.dpri = 0;
  113.     taskp.did = 2;
  114.     taskp.dpc = wait_task;
  115.     taskp.dac2 = 0;
  116.     taskp.dstb = wait_stack;
  117.     taskp.dsflt = -1;
  118.     taskp.dssz = 1024;
  119.     taskp.dflgs = 0;
  120.     taskp.dres = 0;
  121.     taskp.dnum = 1;
  122.  
  123.     ac2 = &taskp;
  124.     ier = sys($TASK, &ac0, &ac1, &ac2);
  125.     if (ier) sys_emes(ier);
  126.  
  127. }
  128.  
  129.